<%@ page contentType="text/html; charset=gb2312" import="java.sql.*"%>
<html>
<head>
<title>添加图书信息</title>
</head>
<style type="text/css">
body {
    background-repeat: no-repeat;
    background-attachment: fixed;
    background-position: center;
    text-align: center;
    margin: 0px auto;
}
</style>
<body background=4.jpg>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <form action="8.jsp" method="post">
        <div align="center"></div>
        <table align="center" width="30%" border="1">
            <caption>
                <font face="华文新魏">添加信息</font>
            </caption>
            <tr>
                <th width="30%">编号：</th>
                <td width="30%"><input name="bno" type="text">*</td>
            </tr>
            <tr>
                <th>书名：</th>
                <td><input name="name" type="text">*</td>
            </tr>
            <tr>
                <th>作者：</th>
                <td><input name="author" type="text"></td>
            </tr>
            <tr>
                <th>价格：</th>
                <td><input name="price" type="text"></td>
            </tr>
            <tr>
                <th colspan="2"><input type="submit" name="submit" value="添加"
                    style="width: 50px;"> <input type="reset" value="重置"
                    style="width: 50px;"> <a href=5.jsp> 返回</a></th>
            </tr>
        </table>
    </form>

    <%  ResultSet rs;
    Statement sql; Connection con;
request.setCharacterEncoding("gb2312");
String submit=request.getParameter("submit");
try{  Class.forName("com.mysql.jdbc.Driver");
}
catch(Exception e){
   out.println("忘记把MySQL数据库的JDBC-数据库驱动程序复制到JDK的扩展目录中");
}
if(submit!=null&&!submit.equals(""))
{
      String name=request.getParameter("name");
      String author=request.getParameter("author");  
      String price=request.getParameter("price");   
      String bno=request.getParameter("bno"); 
      float p=Float.parseFloat(price);
    if(bno!=""&&name!="")
    {
        if(bno.length()<8 && name.length()<20 && author.length()<20 && price.length()<20)
        { String uri= "jdbc:mysql://127.0.0.1/library";
        String user="root";
        String password="";
            Class.forName("com.mysql.jdbc.Driver");
            con=DriverManager.getConnection(uri,user,password);
             sql=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
             String condition="INSERT INTO "+"information "+" VALUES "+"("+"'"+bno+"','"+name+"','"+author+"',"+p+")";
             sql.executeUpdate(condition);
             rs=sql.executeQuery("SELECT * FROM "+"information");
             ResultSetMetaData metaData=rs.getMetaData();
             int columnCount=metaData.getColumnCount();
             String []columnName = new String[columnCount];
             out.print(columnCount);
             con.close();
        }       
    }}      
%>
</body>
</html>